package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import util.DBUtil;

public class ChartsDao {
			PreparedStatement pstmt=null;
			DBUtil db= new DBUtil();
			Connection conn=db.open();
			ResultSet rs=null;
		
	public List<Map> findCompany(String area){
		
		String sql="select company_id,company_name from company where area='"+area+"'";
		List<Map> list=new ArrayList<Map>();
		try {
			pstmt=conn.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()){
				Map<String,Object> map=new HashMap<String, Object>();
				
				map.put("company_id", rs.getString(1));
				map.put("company_name", rs.getString(2));
				list.add(map);
				}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			db.close();
		}
		
		return list;		
	}
	
	public List<Map> findOutlet(String company_id){
		List<Map> list=new ArrayList<Map>();
		String sql="select outlet_id,outlet_name from outlet,company  where outlet.company_id=company.company_id and outlet.company_id='"+company_id+"'";
		try {
			pstmt=conn.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()){
				Map<String,Object> map=new HashMap<String,Object>();
				
				map.put("outlet_id", rs.getInt(1));
				map.put("outlet_name", rs.getString(2));
				list.add(map);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			db.close();
		}
		return list;
		
	}
}
